package com.better517na.elasticseach.controller;

import com.better517na.component.security.utils.GsonUtil;
import com.better517na.elasticseach.context.ElasticSearchContext;
import com.better517na.elasticseach.context.InputParam;
import com.better517na.elasticseach.handlers.Handler;
import com.better517na.elasticseach.service.InvokeMethodService;
import com.google.gson.Gson;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Api(tags = "elasticseach", description = "导出导入接口")
@Controller
@RequestMapping(value = "/api", name = "elasticseach服务api")
public class ElasticseachController {


    @Autowired
    private InvokeMethodService invokeMethodService;

    /**
     * 获取调用信息.
     *
     * @return
     */
    @ApiOperation(value = "获取调用信息", notes = "测试接口")
    @RequestMapping(value = "/getMessage", method = RequestMethod.POST)
    @ResponseBody
    public String getMessage(@RequestBody String msg) {
        return msg;
    }

    @ApiOperation(value = "执行导入，导出", notes = "导入，导出接口")
    @RequestMapping(value = "/esExcute", method = RequestMethod.POST)
    @ResponseBody
    public String excute(@RequestBody InputParam inputParam){
        try {
            invokeMethodService.excute(inputParam);
        } catch (Exception e) {
            e.printStackTrace();
            return e.getMessage();
        }
        return "success";
    }

}
